package xin.alum.aim.redis;

import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import xin.alum.aim.groups.Session;
import xin.alum.aim.groups.Sessions;
import xin.alum.aim.util.JSONUtils;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.MessageListener;

/**
 * 集群环境下，监控多设备登录情况，控制是否其余终端下线的逻辑
 */
class KickMessageListener implements MessageListener {

    @Autowired
    Sessions sessions;
    @Autowired
    Jackson2JsonRedisSerializer json;

    @SneakyThrows
    @Override
    public void onMessage(org.springframework.data.redis.connection.Message redisMessage, byte[] bytes) {
        Session s = (Session) json.deserialize(redisMessage.getBody());
        sessions.kick(s);
    }
}
